﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ESOL.Common;
using ESOL.Business.Prod;
using ESOL.Common.Entity;

namespace ESOL.WinUI.Manufacture
{
    public partial class frmManageWorkCenters : BaseForm.frmBaseMdiBusinessForm
    {
        #region vars

        #endregion

        #region ctors
        public frmManageWorkCenters()
        {
            InitializeComponent();
        }
        #endregion

        #region functions
        private string GetCondition()
        {
            string sCondition = "";
            if (!string.IsNullOrEmpty(txtName.Text))
            {
                sCondition += "and NAME='"+txtName.Text+"' ";
            }
            if (!string.IsNullOrEmpty(txtCode.Text))
            {
                sCondition += "and CODE='" + txtCode.Text + "' ";
            }
            if (!string.IsNullOrEmpty(cmbType.SelectedValue.ToString()))
            {
                sCondition += "and TYPE='" + cmbType.SelectedValue.ToString() + "' ";
            }
            if (cbActive.Checked)
            {
                sCondition += "and ACTIVE=1 ";
            }
            else
            {
                sCondition += "and ACTIVE=0 ";
            }
            return sCondition;
        }

        private void BindCombobox()
        {
            UICommon.UICommonFunctions.BindComboboxByEnum(cmbType, typeof(WorkCentersType), typeof(int), true);
            UICommon.UICommonFunctions.BindGridComboboxByEnum(repositoryItemGridLookUpEdit1, typeof(WorkCentersType), typeof(int), false);
            
        }

        private void BindGrid()
        {
            string sCondition = GetCondition();
            List<ProdWorkcentersEntity> list = new List<ProdWorkcentersEntity>();
            list = ProdWorkcentersBs.GetAllForCondition(sCondition, "", txtRowCount.Text);
            gvMain.DataSource = list;
        }
        #endregion

        #region events
        protected override void OnShown(EventArgs e)
        {
            base.OnShown(e);
            BindCombobox();
        }

        protected override void Click_Query()
        {
            BindGrid();
        }

        protected override void Click_New()
        {
            //base.Click_New();
            frmMaintainWorkCenters frm = new frmMaintainWorkCenters(ActionType.New);
            if (frm.ShowDialog() == DialogResult.OK)
            {
                BindGrid();
            }
        }

        protected override void Click_View()
        {
            ProdWorkcentersEntity m = (ProdWorkcentersEntity)gridView1.GetFocusedRow();
            frmMaintainWorkCenters frm = new frmMaintainWorkCenters(ActionType.View, m);
            frm.ShowDialog();
        }

        protected override void Click_Modify()
        {
            ProdWorkcentersEntity m = (ProdWorkcentersEntity)gridView1.GetFocusedRow();
            frmMaintainWorkCenters frm = new frmMaintainWorkCenters(ActionType.Modify, m);
            if (frm.ShowDialog() == DialogResult.OK)
            {
                BindGrid();
            }
        }

        protected override void Click_Import()
        {
            base.Click_Import();
        }

        protected override void Click_Export()
        {
            base.Click_Export();
        }
        #endregion
    }
}
